import {
  enableUpdateSparePrice,
  updateAntiFakeQueryStrategy,
  updateAutoCheckCancelOrder,
  updateAutoCheckEndOrder,
  updateAutoSureReceiveOrder,
  updateCreateOrderStrategy,
  updateSpareApplyStrategy,
  updateViewKnowStrategy,
  updateallowUpdateSnCode
} from '@/api/network'
import { ref } from 'vue'

export const useUpdateCreateOrderStrategy = () => {
  // 更新创建工单策略加载
  const updateCreateOrderStrategyLoading = ref(false)

  // 是否允许创建工单
  const isAllowCreateOrder = ref(false)

  /**
   * 批量更新创建工单策略
   * @param {Array<string>} networkIds - 部门id集合
   */
  const multipleUpdateCreateOrderStrategy = async (networkIds: Array<string>) => {
    updateCreateOrderStrategyLoading.value = true
    const res = await updateCreateOrderStrategy(isAllowCreateOrder.value, networkIds)
    updateCreateOrderStrategyLoading.value = false
    return res.data
  }

  return {
    isAllowCreateOrder,
    updateCreateOrderStrategyLoading,
    multipleUpdateCreateOrderStrategy,
  }
}

export const useAllowAntiFakeQueryStrategy = () => {
  // 允许防伪查询加载
  const allowAntiFakeQueryLoading = ref(false)

  // 是否允许防伪查询
  const isAllowAntiFakeQuery = ref(false)

  /**
   * 批量更新防伪查询策略
   * @param {Array<string>} ids - 部门id集合
   */
  const multipleUpdateAntiFakeQueryStrategy = async (ids: Array<string>) => {
    allowAntiFakeQueryLoading.value = true
    const res = await updateAntiFakeQueryStrategy(isAllowAntiFakeQuery.value, ids)
    allowAntiFakeQueryLoading.value = false
    return res.data
  }

  return {
    isAllowAntiFakeQuery,
    allowAntiFakeQueryLoading,
    multipleUpdateAntiFakeQueryStrategy,
  }
}

export const useReceiveOrderStrategy = () => {
  // 批量更新部门接单策略加载
  const updateAutoSureReceiveOrderLoading = ref(false)

  // 是否自动接单：false-手动确认，true-自动接单
  const autoSureReceiveOrder = ref(true)

  /**
   * 批量更新部门接单策略
   * @param {Array<string>} ids - 部门id集合
   */
  const updateAutoSureReceiveOrderFn = async (ids: Array<string>) => {
    updateAutoSureReceiveOrderLoading.value = true
    const res = await updateAutoSureReceiveOrder(autoSureReceiveOrder.value, ids)
    updateAutoSureReceiveOrderLoading.value = false
    return res.data
  }

  return {
    autoSureReceiveOrder,
    updateAutoSureReceiveOrderLoading,
    updateAutoSureReceiveOrderFn,
  }
}

export const useAutoCheckEndOrder = () => {
  // 批量自动审核结单策略加载
  const autoCheckEndOrderLoading = ref(false)

  // 是否自动审核结单：false-手动审核，true-自动审核
  const autoCheckEndOrder = ref(false)

  /**
   * 批量更新自动审核结单策略
   * @param {Array<string>} ids - 部门id集合
   */
  const autoCheckEndOrderFn = async (ids: Array<string>) => {
    autoCheckEndOrderLoading.value = true
    const res = await updateAutoCheckEndOrder(autoCheckEndOrder.value, ids)
    autoCheckEndOrderLoading.value = false
    return res.data
  }

  return {
    autoCheckEndOrder,
    autoCheckEndOrderLoading,
    autoCheckEndOrderFn,
  }
}

export const useAutoCheckCancelOrder = () => {
  // 批量自动审核取消工单策略加载
  const autoCheckCancelOrderLoading = ref(false)

  // 是否自动审核取消工单：false-手动审核，true-自动审核
  const autoCheckCancelOrder = ref(false)

  /**
   * 批量更新自动审核取消工单策略
   * @param {Array<string>} ids - 部门id集合
   */
  const autoCheckCancelOrderFn = async (ids: Array<string>) => {
    autoCheckCancelOrderLoading.value = true
    const res = await updateAutoCheckCancelOrder(autoCheckCancelOrder.value, ids)
    autoCheckCancelOrderLoading.value = false
    return res.data
  }

  return {
    autoCheckCancelOrder,
    autoCheckCancelOrderLoading,
    autoCheckCancelOrderFn,
  }
}

export const useUpdateChangeSparePriceStrategy = () => {
  // 批量更新允许更改备件价格策略加载
  const enableUpdateSparePriceLoading = ref(false)

  // 是否允许更改备件价格：false-关闭，true-允许修改
  const isEnableUpdateSparePrice = ref(true)

  /**
   * 批量更新允许更改备件价格策略
   * @param {Array<string>} ids - 部门id集合
   */
  const enableUpdateSparePriceFn = async (ids: Array<string>) => {
    enableUpdateSparePriceLoading.value = true
    const res = await enableUpdateSparePrice(isEnableUpdateSparePrice.value, ids)
    enableUpdateSparePriceLoading.value = false
    return res.data
  }

  return {
    isEnableUpdateSparePrice,
    enableUpdateSparePriceLoading,
    enableUpdateSparePriceFn,
  }
}

export const useUpdatSpareApplyStrategy = () => {
  // 更新申请物料策略加载
  const updateSpareApplyStrategyLoading = ref(false)

  // 是否允许申请物料
  const isAllowSpareApply = ref(false)

  /**
   * 更新申请物料策略
   * @param {Array<string>} ids - 部门id集合
   */
  const multipleUpdateSpareApplyStrategy = async (ids: Array<string>) => {
    updateSpareApplyStrategyLoading.value = true
    const res = await updateSpareApplyStrategy(isAllowSpareApply.value, ids)
    updateSpareApplyStrategyLoading.value = false
    return res.data
  }

  return {
    isAllowSpareApply,
    updateSpareApplyStrategyLoading,
    multipleUpdateSpareApplyStrategy,
  }
}

export const useUpdateViewKnowStrategy = () => {
  // 更新查看知识库策略加载
  const updateViewKnowStrategyLoading = ref(false)

  // 是否允许查看知识库
  const isAllowViewKnow = ref(false)

  /**
   * 批量更新查看知识库策略
   * @param {String} ids - 部门id集合
   */
  const multipleUpdateViewKnowStrategy = async (ids: Array<string>) => {
    updateViewKnowStrategyLoading.value = true
    const res = await updateViewKnowStrategy(isAllowViewKnow.value, ids)
    updateViewKnowStrategyLoading.value = false
    return res.data
  }

  return {
    isAllowViewKnow,
    updateViewKnowStrategyLoading,
    multipleUpdateViewKnowStrategy,
  }
}
export const useUpdateallowUpdateSnCodeFun = () => {
  // 批量更新部门接单策略加载
  const updateAllowUpdateSnCodeLoading = ref(false)

  // 允许修改序列号：false-不允许，true-允许,示例值(true)
  const allowUpdateSnCode = ref(true)

  /**
   * 批量更新部门接单策略
   * @param {Array<string>} ids - 部门id集合
   */
  const updateallowUpdateSnCodeFn = async (ids: Array<string>) => {
    updateAllowUpdateSnCodeLoading.value = true
    const res = await updateallowUpdateSnCode(allowUpdateSnCode.value, ids)
    updateAllowUpdateSnCodeLoading.value = false
    return res.data
  }

  return {
    allowUpdateSnCode,
    updateAllowUpdateSnCodeLoading,
    updateallowUpdateSnCodeFn,
  }
}